<?php
/**
 * Nordic Repository
 * 
 * LICENSE
 * 
 * The new BSD license is applied on this source-file. For further
 * information please visit http://license.nordic-dev.de/newbsd.txt
 * or send an email to andre.moelle@gmail.com.
 */

/**
 * Necessary includes.
 */
Zend_Loader::loadClass('Nordic_I18n_Exception');
Zend_Loader::loadClass('Nordic_I18n_Adaptable');
Zend_Loader::loadClass('Nordic_I18n_Adapter');

/**
 * Class which is used to provide methods for internationalization.
 * 
 * @category   Nordic
 * @package    Nordic_I18n
 * @copyright  2007 Nordic Development
 * @license    http://license.nordic-dev.de/newbsd.txt (New-BSD license)
 * @author     Andre Moelle <andre.moelle@gmail.com>
 * @version    $Id: I18n.php 3 2007-07-08 09:21:42Z andre.moelle $
 */
class Nordic_I18n
{
	/**
	 * Adapter which is used by this class.
	 * 
	 * @var Nordic_I18n_Adaptable
	 */
	private $_adapter;
	
	/**
	 * Instance of this class.
	 * 
	 * @var Nordic_I18n
	 */
	private static $_instance;
	
	/**
	 * Constructor.
	 * 
	 * Sets the adapter.
	 * 
	 * @param Nordic_I18n_Adaptable $adapter adapter
	 * @return void
	 */
	private function __construct (Nordic_I18n_Adaptable $adapter)
	{
		$this->setAdapter($adapter);
	}
	
	/**
	 * Returns the adapter if one exists.
	 * 
	 * If there is no adapter available a "Nordic_I18n_Exception" will
	 * be thrown.
	 * 
	 * @throws Nordic_I18n_Exception
	 * @return Nordic_I18n_Adaptable
	 */
	public function getAdapter ()
	{
		if($this->_adapter == null)
		{
			throw new Nordic_I18n_Exception('There is no adapter.');
		}
		
		return $this->_adapter;
	}
	
	/**
	 * @see Nordic_I18n_Adaptable::getLanguage()
	 */
	public function getLanguage ()
	{
		return $this->getAdapter()->getLanguage();
	}
	
	/**
	 * @see Nordic_I18n_Adaptable::getLanguages()
	 */
	public function getLanguages ()
	{
		return $this->getAdapter()->getLanguages();
	}
	
	/**
	 * Returns an instance of this class.
	 * 
	 * @param Nordic_I18n_Adaptable $adapter optional adapter
	 * @return Nordic_I18n
	 */
	public static function getInstance ($adapter = null)
	{
		if(self::$_instance == null)
		{
			self::$_instance = new self($adapter);
		}
		
		return self::$_instance;
	}
	
	/**
	 * @see Nordic_I18n_Adaptable::isValid()
	 */
	public function isValid ($language)
	{
		return $this->getAdapter()->isValid($language);
	}
	/**
	 * Sets the adapter.
	 * 
	 * @param Nordic_I18n_Adaptable $adapter new adapter
	 * @return void
	 */
	public function setAdapter (Nordic_I18n_Adaptable $adapter)
	{
		$this->_adapter = $adapter;
	}
	
	/**
	 * @see Nordic_I18n_Adaptable::setLanguage()
	 */
	public function setLanguage ($language)
	{
		$this->getAdapter()->setLanguage($language);
	}
	
}
?>